#include <iostream>
using namespace std;
#include <vector>
#include <algorithm>

class Solution 
{
public:
    long long numberOfRightTriangles(vector<vector<int>>& grid) 
    {
        int n = grid.size(), m = grid[0].size();
        vector<int> col(m);
        for (int i = 0; i < n; i++) 
        {
            for (int j = 0; j < m; j++) 
            {
                col[j] += grid[i][j];
            }
        }
        long long res = 0;
        for (int i = 0; i < n; i++) 
        {
            int row = 0;
            for (int n = 0; n < grid[i].size(); n++)
            {
                row += grid[i][n];
            }

            for (int j = 0; j < m; j++) 
            {
                if (grid[i][j] == 1) 
                {
                    res += (row - 1) * (col[j] - 1);
                }
            }
        }
        return res;
    }
};


int main()
{
    vector<vector<int>> vv = { {0,1,0},{0,1,1},{0,1,0} };
    Solution s;
    cout << s.numberOfRightTriangles(vv);
    return 0;
}
